#include"TcpServer.hpp"
#include"Calculator.hpp"
#include<memory>
Calculator cal;
void defaulthandler(std::weak_ptr<Connection> connect)
{
    if(connect.expired())return ;
        std::shared_ptr<Connection> connect_ptr=connect.lock();
    
std::cout<<"上层获取到数据!"<<std::endl;
std::string& package=connect_ptr->Inbuffer();
std::cout<<package<<std::endl;

std::string response_str=cal.Calculate(package);
std::cout<<"上层处理完数据！"<<std::endl;
std::cout<<response_str<<std::endl;
//处理完数据后，要把数据写到发送缓冲区（用户层）
connect_ptr->AppendOutbuffer(response_str);

//绕后回进服务器里面发送数据（把数据从用户层发送缓冲区拷贝到内核的发送缓冲区）
auto connection=connect_ptr->tcpserver_ptr.lock();
connection->Sender(connect_ptr);

}
int main()
{
    std::shared_ptr<TcpServer> epoll_ser(new TcpServer(defaulthandler));
    epoll_ser->Init();
    epoll_ser->Pool();     
    return 0;
}